﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AdminDor : System.Web.UI.Page
{
    PagedDataSource pds = new PagedDataSource();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        string sql = string.Format("select * from Doctor order by AutoID");
        DataSet ds = DBHelper.GetDataSet(sql);
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 20;
        pds.CurrentPageIndex = Convert.ToInt32(ViewState["Page"]);
        this.lblTotle.Text = "共有" + pds.PageCount.ToString() + "页";
        this.lblCurrent.Text = "当前第" + (pds.CurrentPageIndex + 1).ToString() + "页";
        ViewState["PageCount"] = pds.PageCount;
        Enabled();
        DataList1.DataSource = pds;
        DataBind();
    }

    private void Enabled()
    {
        this.Button1.Enabled = true;
        this.Button2.Enabled = true;
        if (pds.IsFirstPage)
        {
            this.Button1.Enabled = false;
        }
        if (pds.IsLastPage)
        {
            this.Button2.Enabled = false;
        }
    }

    protected void Btnss_Click(object sender, EventArgs e)
    {
        string sql = string.Format("select * from Doctor where Name like'%{0}%' or ID='{1}'", this.Txtss.Text, this.Txtss.Text);
        DataSet ds = DBHelper.GetDataSet(sql);
        DataList1.DataSource=ds;
        DataBind();
        ds.Clone();
    }

    //首页
    protected void Button3_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = 0;
        Bind();
    }

    //上一页
    protected void Button1_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) - 1;
        Bind();
    }

    //下一页
    protected void Button2_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) + 1;
        Bind();
    }

    //尾页
    protected void Button4_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["PageCount"]) - 1;
        Bind();
    }
}